/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/***************************************************************************
 * Name: proxy_field.h
 *
 * Purpose: field for proxy side
 *
 * Developer:
 *   wen.gu , 2021-05-16
 *
 * TODO:
 *
 ***************************************************************************/

/******************************************************************************
 **    INCLUDES
 ******************************************************************************/
#ifndef __PROXY_FIELD_H__
#define __PROXY_FIELD_H__

#include "object_subscriber.h"
#include "proxy_requester.h"
/******************************************************************************
 **    MACROS
 ******************************************************************************/


/******************************************************************************
 **    TYPE DEFINITIONS
 ******************************************************************************/



/******************************************************************************
 **    CLASSES/FUNCTIONS DEFINITIONS
 ******************************************************************************/
template<typename SimpleType, FieldId field_id>
class ProxyField: public ObjectSubscriber<SimpleType>
{
public:
    ProxyField(ProxyRequesterPtr proxy)
    :ObjectSubscriber<SimpleType>(proxy, MessageType::kFieldNotify, MAKE_FIELD_ID(field_id))
    {
        /** todo something */
    }

    ~ProxyField()
    {
        /** todo something */
    }
public:
    Return<SimpleType> Set(const SimpleType& val)
    {
        if (proxy_)
        {
            return proxy_->MethodCall(MessageType::kFieldSet, message_id_, val);
        }
        return std::move(Return<SimpleType>(std::future<SimpleType>(), -1, nullptr));
    }

    Return<SimpleType> Get(void)
    {
        if (proxy_)
        {
            return proxy_->MethodCall(MessageType::kFieldGet, message_id_, val);
        }

        return std::move(Return<SimpleType>(std::future<SimpleType>(), -1, nullptr));        
    }
};

#endif /** !__PROXY_FIELD_H__ */

